/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DBMS;
import java.sql.*;
/**
 *
 * @author roque
 */
public class DataBaseManager {
    private static String driver="org.postgresql.Driver";
    private static String cadenacon="jdbc:postgresql://localhost:5432/postgres";
    private static String userPostgres="postgres";
    private static String passPostgres="postgres";
    private static Connection cn;
    private static DBMS.DataBaseManager instance  = null;
    
    private DataBaseManager(){
    }
    
    static public DBMS.DataBaseManager getInstance(){
        if (null ==  DBMS.DataBaseManager.instance){
               DBMS.DataBaseManager.instance = new DBMS.DataBaseManager();
        }
        getConexion();
        return DBMS.DataBaseManager.instance;
    }
    
    public static boolean getConexion(){
        
//        System.out.println(driver);
        try{
            Class.forName(driver);
            cn=DriverManager.getConnection(cadenacon,userPostgres,passPostgres);
            System.out.println("Conexion a la base de datos Ejemplo realizada con exito! ");
            return true;
            
        }
        catch(Exception e){
            System.out.println("Se ha producido un error en la conexion a la base de datos Ejemplo! ");
        }
        return false;
    }
    
    public void cierraConexion(Connection cn){
        try{
            DBMS.DataBaseManager.cn.close();
            cn = null;
        }
        catch(SQLException e){
            e.printStackTrace();
        }
    }
    
}
